<?php
//URL跳转
function goURL($url='', $msg='')
{
	$url = ($url)?$url:$_SERVER['HTTP_REFERER'];
	$url = ($url)?$url:'/';
	$JSstr = '';
	if($msg)
	{
		$JSstr .= '<meta http-equiv="Content-Type" content="text/html; charset=utf-8">';
		$JSstr .= "<script>alert('$msg');</script>\n";
	}
	$JSstr .= "<script>location.href='$url'</script>\n";
	$JSstr .= "<meta http-equiv=\"refresh\" content=\"1; url=$url\">";
	echo $JSstr;
	exit();
}


//html下拉菜单列表
function html_options($arr, $set='AaBa005353dffs')
{
	foreach($arr as $k=>$v)
	{
		if(is_array($v))
		{
			$options[] = "<optgroup title='$k'>";
			foreach($v as $k2=>$v2)
			{
				$selected = ($set == $k)?'selected':'';
				if(is_array($set))$selected = (in_array($k, $set))?'selected':'';
				$options[] = "<option value='$k2' $selected>$v2</option>";
			}
			$options[] = "</optgroup>";
		}
		else
		{
			$selected = ($set == $k)?'selected':'';
			if(is_array($set))$selected = (in_array($k, $set))?'selected':'';
			$options[] = "<option value='$k' $selected>$v</option>";
		}
	}

	return implode("\n", $options);
}

//html下拉菜单生成
function html_select($idname='select', $options='', $set='AaBa00fte6t5', $js='', $size=0)
{
	$size = ($size==0)?'':"size='$size'";
	$select = "<select name='$idname' id='$idname' $size $js style='font-size:12px;'>\n";
	if(is_array($options))$select .= html_options($options, $set);
	$select .= "</select>\n";

	return $select;
}


//radio列表
function html_radios($name, $array, $selected="", $sepreator="&nbsp;&nbsp;")
{
	$html = "";
	foreach($array as $k => $v)
	{
		$checked = "";
		if($k == $selected)$checked = "checked";
		$html .= "<label><input name=\"$name\" type=\"radio\" value=\"$k\" $checked> $v</label> $sepreator \n";
	}
	return $html;
}

//check列表
function html_checkboxes($name, $array, $selected=array(), $sepreator="&nbsp;&nbsp;")
{
	$html = "";
	//$sel = explode(',', $selected);
	foreach($array as $k => $v)
	{
		$checked = "";
		for($i=0;$i<count($selected);$i++)
		{
			if($selected[$i] == $k)$checked = "checked";
		}
		$html .= "<label><input name=\"$name\" type=\"checkbox\" value=\"$k\" $checked> $v</label> $sepreator \n";
	}
	return $html;
}

//禁止浏览器缓冲,ajax输出必须使用
function NoCacheHeaders()
{
	header( "Cache-Control: no-cache, must-revalidate" );
	header( "Pragma: no-cache" );
	header( "Expires: Mon, 26 Jul 1997 05:00:00 GMT" );
	header( "Last-Modified: " . gmdate( "D, d M Y H:i:s" ) . "GMT" );

}


//从URI请求分析主模块
function moduleCheck()
{
	global $conf;
	$uri = explode('/', $_SERVER['QUERY_STRING']);
	$module = ($_GET['module'])?$_GET['module']:$uri[0];
	if(!is_file(ROOT_PATH."/modules/$module.php") && !is_file(ROOT_PATH."/modules/$module/$module.php"))$module = $conf['default_module'];
	if(is_file(ROOT_PATH."/modules/$module/$module.php"))$module="$module/$module";
	return $module;
}


//分析次要模块
function submoduleCheck()
{
	$uri = explode('/', $_SERVER['QUERY_STRING']);
	$module = ($_GET['module'])?$_GET['module']:$uri[0];
	$sub = ($_GET['sub'])?$_GET['sub']:$uri[1];
	if(is_file(ROOT_PATH."/modules/$module/$sub.php"))return $sub;
}

//将URL重写
function URLRewrite()
{
	global $conf;
	$get = $_GET;
	$module = $get['module'];
	$sub = $get['sub'];
	unset($get['module']);
	unset($get['sub']);
	$uri = $conf['site_url']."/?$module/$sub".implode('/', $get);

	return $uri;
}

//模块装载
function module($module)
{
	global $conf;
	$module = strtolower($module);
	$module_file = ROOT_PATH."/modules/$module.php";
	if(file_exists($module_file))return $module_file;
	else return ROOT_PATH."/modules/$conf[default_module].php";
	//else echo "Module $module not found!";
}

//设定cookie
function scookie($name, $value='', $time=null)
{
	global $conf;
	return setcookie($name, $value, $time, $conf['cookie_path'], $conf['cookie_host']);
}

function extfunc($func)
{
	global $conf;
	$path = ROOT_PATH.'/'.$conf['extend_path']."/functions.$func.php";
	if(is_file($path))return $path;
	else echo "Function $func not found!";
}


function extclass($func)
{
	global $conf;
	$path = ROOT_PATH.'/'.$conf['extend_path']."/class.$func.php";
	if(is_file($path))return $path;
	else echo "Class $func not found!";
}

function getip()
{
	if ($HTTP_SERVER_VARS["HTTP_X_FORWARDED_FOR"])
	$ip = $HTTP_SERVER_VARS["HTTP_X_FORWARDED_FOR"];
	elseif ($HTTP_SERVER_VARS["HTTP_CLIENT_IP"])
	$ip = $HTTP_SERVER_VARS["HTTP_CLIENT_IP"];
	elseif ($HTTP_SERVER_VARS["REMOTE_ADDR"])
	$ip = $HTTP_SERVER_VARS["REMOTE_ADDR"];
	elseif (getenv("HTTP_X_FORWARDED_FOR"))
	$ip = getenv("HTTP_X_FORWARDED_FOR");
	elseif (getenv("HTTP_CLIENT_IP"))
	$ip = getenv("HTTP_CLIENT_IP");
	elseif (getenv("REMOTE_ADDR"))
	$ip = getenv("REMOTE_ADDR");
	else
	$ip = "Unknown";
	return $ip;

}

function showphoto($photo,$wh,$nopic='',$class='')
{
	$class=empty($class)?'':'class="'.$class.'"';
	$nopic=empty($nopic)?'':'<img src="'.$nopic.'" '.$class.' width="'.$wh.'" BORDER="0">';
	if(!file_exists($photo)){
		return $nopic;
	}
	$i=$photo;
	$s=getimagesize($i);
			
	if($s[0]<=$wh && $s[1]<=$wh){
		$bs="";
	}else{
		if($s[0]>=$s[1]){
			$bs=" width='".$wh."' ";
		}else{
			$bs=" height='".$wh."' ";
		}
	}
	return '<IMG SRC="'.$i.'" '.$bs.'  BORDER="0" '.$class.'>';
}
 

function wordShift($content)
{//过滤敏感词
	//echo ROOT_PATH."/inc/filter_words.txt";

        $s= "*";
        $word=array('艳照门','窃听','疆独','藏独','高干子弟','高干子女','枪支弹药','血腥图片','反政府','禁书','无界浏览器','特码','反共','成人片','成人电影','换妻','三级片','天鹅之旅','盘古乐队','高校暴乱','高校群体事件','大学骚乱','高校骚乱','催情药','拍肩神药','春药','窃听器材','身份证生成器','枪决现场','出售手枪','麻醉枪','办理证件','自杀指南','自杀手册','张小平','佳静安定片','蒙汗药粉','古方迷香','强效失意药','迷奸药','透视眼镜','远程偷拍','自制手枪','子女任职名单','激情小电影','黄色小电影','色情小电影','PK黑社会','恶搞晚会','枪决女犯','投毒杀人','强硬发言','出售假币','监听王','昏药','侦探设备','麻醉钢枪','反华','官商勾结','升达毕业证','手机复制','戴海静','三唑仑','麻醉药','麻醉乙醚','短信群发器','帝国之梦','毛一鲜','黎阳平','色情服务','对日强硬','出售枪支','迷药','摇头丸','西藏天葬','鬼村','军长发威','法轮功','李洪志','大纪元','真善忍','新唐人','肉棍','淫靡','淫水','六四事件','迷昏药','窃听器','买卖枪支','退党','六合彩','k粉');
		//print_r($filter_word);
        foreach($word as $keys)
        {
			$content=eregi_replace($keys,$s,$content);
        }

	return $content;
}
?>